package com.sunchen.asc.service.item.repository;

import com.sunchen.asc.service.item.domain.ItemDepartment;
import com.sunchen.asc.service.item.vo.ItemDepartmentVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ItemDepartmentRepository extends JpaRepository<ItemDepartment,Long> {

    @Query("select count(t.id) from ItemDepartment t where (t.name = ?1 or t.code = ?2) and t.deleteFlag = ?3")
    Long countByNameOrCodeAndDeleteFlag(String name,String code,int deleteFlag);

    Long countByNameAndDeleteFlag(String name,int deleteFlag);

    Long countByCodeAndDeleteFlag(String name,int deleteFlag);

    Long countByParentIdAndDeleteFlag(Long parentId,int deleteFlag);

    @Query("select new com.sunchen.asc.service.item.vo.ItemDepartmentVo(t.id,t.name,t.parentId,t.code,t.description) from ItemDepartment t where t.deleteFlag = 0")
    List<ItemDepartmentVo> findAllVo();
}
